
Appendix C. Digging Through Your Garbage

From:
  Killer Game Programming in Java

  Dr. Andrew Davison
  Dept. of Computer Engineering
  Prince of Songkla University
  Hat yai, Songkhla 90112, Thailand
  E-mail: ad@fivedots.coe.psu.ac.th
  Web Site for the book: http://fivedots.coe.psu.ac.th/~ad/jg

[ This appendix does *NOT* appear in the hard copy of the book. ]


If you use this code, please mention my name, and include a link
to the book's Web site.

Thanks,
  Andrew


============================
This directory contains:

* MemoryLeak.java
    // an example that generates a slowly growing memory leak

  Compile: javac MemoryLink.java
  Run:     java MemoryLink

* FPSBehaviour
    /* A Java 3D behaviour which generates frame rate information
       every second. This must be added to a Java 3D application,
       as explained in the appendix. */

==========================
Other Examples

The examples include JumpingJack and FPShooter3D.

JumpingJack is from chapter 12, available at:
http://fivedots.coe.psu.ac.th/~ad/jg/ch062/

FPShooter3D is from chapter 24, available at:
http://fivedots.coe.psu.ac.th/~ad/jg/ch15/

==========================
Garbage Collection and Profiling Calls

No changes need to be made to the applications.
Garbage collection logs will be saved in the text file gc.txt.
Profiling logs will be saved in the text file java.hprof.txt.

// MemoryLeak
java -Xloggc:gc.txt MemoryLeak

java -Xrunhprof:heap=sites,cpu=samples MemoryLeak

java -Xrunhprof:help


// JumpingJack
java -Xloggc:gc.txt JumpingJack

java -Xloggc:gc.txt -Xms30m -Xmx30m 
     -XX:NewSize=6m -XX:MaxNewSize=6m JumpingJack 
        // all on 1 line


// FPShooter3D
java -cp %CLASSPATH%;ncsa\portfolio.jar -Xloggc:gc.txt FPShooter3D

java -cp %CLASSPATH%;ncsa\portfolio.jar 
     -Xloggc:gc.txt -Xms24m -Xmx24m 
     -XX:NewSize=3m  -XX:MaxNewSize=3m FPShooter3D
        // all on 1 line

java -cp %CLASSPATH%;ncsa\portfolio.jar 
     -XX:+UseParallelGC 
     -Xloggc:gc.txt FPShooter3D
        // all on 1 line

java -cp %CLASSPATH%;ncsa\portfolio.jar 
     -XX:+UseParallelGC -XX:MaxGCPauseMillis=10 
     -Xloggc:gc.txt FPShooter3D
        // all on 1 line


==========================
GC Visualization Tool

For viewing the garbage collection logs, I used HPjtune, from 
http://www.hp.com/products1/unix/java/java2/hpjtune/

Start it:
  java -jar HPjtune.jar

Load gc.txt

==========================
Profiling Visualization Tool

For viewing the profiling logs, I used HPjmeter, from 
http://www.hp.com/products1/unix/java/hpjmeter/

Start it:
  java -jar HPjmeter.jar

Load java.hprof.txt

==========================
Using JConsole

JConsole is a standard part of J2SE 5.0.,
in <JAVA_HOME>/bin.

Start the JVM:
  java  -Dcom.sun.management.jmxremote.port=1097 
        -Dcom.sun.management.jmxremote.authenticate=false 
        -Dcom.sun.management.jmxremote.ssl=false
        FPShooter3D
     // all on 1 line

Start JConsole in a separate DOS window:
  jconsole localhost:1097

-----
Last updated: 23rd November 2005
